﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="CSI.Directory.Web.Util"%>
<%@ Import Namespace="CSI.Directory.Core.Model"%>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Directory
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<style>
.tab{padding:10px;color:#3B7899;font-size:17px;border-style:none;}
.active{background-color:#EEE;}
.col{float:left;margin-right:15px}
</style>

<div class="main_center_content">

<div class="left_content">
<% Html.RenderPartial("/Views/Shared/LeftMenu.ascx"); %>     
   <script type='text/javascript'><!--      //<![CDATA[
      var m3_u = (location.protocol == 'https:' ? 'https://www.eaglefordflyer.com/advertise/www/delivery/ajs.php' : 'http://www.eaglefordflyer.com/advertise/www/delivery/ajs.php');
      var m3_r = Math.floor(Math.random() * 99999999999);
      if (!document.MAX_used) document.MAX_used = ',';
      document.write("<scr" + "ipt type='text/javascript' src='" + m3_u);
      document.write("?zoneid=5");
      document.write('&amp;cb=' + m3_r);
      if (document.MAX_used != ',') document.write("&amp;exclude=" + document.MAX_used);
      document.write(document.charset ? '&amp;charset=' + document.charset : (document.characterSet ? '&amp;charset=' + document.characterSet : ''));
      document.write("&amp;loc=" + escape(window.location));
      if (document.referrer) document.write("&amp;referer=" + escape(document.referrer));
      if (document.context) document.write("&context=" + escape(document.context));
      if (document.mmm_fo) document.write("&amp;mmm_fo=1");
      document.write("'><\/scr" + "ipt>");
//]]>--></script><noscript><a href='http://www.eaglefordflyer.com/advertise/www/delivery/ck.php?n=a7029c74&amp;cb=7' target='_blank'><img src='http://www.eaglefordflyer.com/advertise/www/delivery/avw.php?zoneid=5&amp;cb=7&amp;n=a7029c74' border='0' alt='' /></a></noscript>
                      
</div><!--end of left content-->

<div class="right_content">
<a href="#" id="county-link" class="tab active" onclick="Show(2);return false;">Counties</a>
<a href="#" id="category-link" class="tab" onclick="Show(1);return false;">Categories</a>
<a href="#" id="featured-link" class="tab" onclick="Show(3);return false;">Featured</a>
<br /><br />
    <div id="counties" >
     <table width="100%">
                <tr valign="top">
        <%
            var count = 0;
            foreach (var c in (IList<County>) ViewData["Counties"] ){
            count++;%><td width="50%">
          <a class="subcatHead2" href="/Directory/County/<%=c.Name %>"><%=c.Name %>  </a>
          
       

                    <%if (count%2 == 0)
                    {%> 
                        </td></tr><tr valign="top">
                    <%
                    }
                    else{%>
                        </td>
                    <%}%>
                <%} %>
                
            </tr>
        </table>       
    </div>
    <div id="categories" style="display:none">
    <br />
    <div id="toggle">
        <img src='/Assets/Images/plus.gif' style='vertical-align:baseline'/>
        &nbsp;<a class="subcatHead2" href="#" onclick="ShowSubs(); return false;">Expand all categories</a>
    </div>
    <br /><br />

              <div class="col">                
              <% var stop = Math.Ceiling((double)((IList<Category>)ViewData["Categories"]).Where(t => t.ParentId == 0).ToList().Count / 2); 
                count = 0;
                foreach (var c in ((IList<Category>)ViewData["Categories"]).Where(t=>t.ParentId == 0))
                {
                    count++;%>
                    <a class="subcatHead2" href="/Directory/GetCategory/<%=c.Id%>/<%= Url.ToFriendlyUrl(c.Alias)%>"><%=c.Name%></a>

		            <% if(c.Total > 0)
			        {%>
				        (<%=c.Total%>)
                    <%}%>
                    
                    <%--hidden subcategories--%>
                    <%if(((IList<Category>)ViewData["Categories"]).Where(t => t.ParentId == c.Id).ToList().Count > 0){ %>
    		            <div style="display:none" class="sub">
                        <%foreach (var s in ((IList<Category>)ViewData["Categories"]).Where(t => t.ParentId == c.Id))
                            {%>
                                <br />
                                &nbsp;&nbsp;<a class="subcatHead3" href="/Directory/GetCategory/<%=s.Id%>/<%= Url.ToFriendlyUrl(s.Alias)%>"><%=s.Name%></a>

			                    <% if(s.Total > 0)
			                    {%>
				                    (<%=s.Total%>)
                                <%}%>
                        
                            <%}  %>
                        </div>
                    <%} %>
                    
                    <%--start new column if needed--%>
                    <%if (count == stop)
                    {
                        count = 0;
                    %> 
                       </div> 
                <div class="col"> 
                    <%
                    }
                    else{%>
                       <br />
                    <%}%>
                <%} %>              
                </div>
    </div>
    <div id="featured" style="display:none">
        <%
            foreach (var l in ((IList<Listing>)ViewData["Featured"]))
        {%>
        <br />
          <div id="listings">
              <table>
                  <tr>
                      <td colspan="2">
                        <h2><a href="/Directory/Listing/<%=l.Id %>/<%= Url.ToFriendlyUrl(l.Name)%>"><%=l.Name %></a></h2>
                        
                        <div style="font-size:10px;color:#666">
                        <img src="/Assets/Images/clock.png" style="vertical-align:middle" />
                        <%=l.CreateDate.ToLongDateString() %></div>
                      </td>
                  </tr>
                  <tr valign="top">
                    <td>
                        <div style="border:solid 5px white; width:100px;height:100px;overflow:hidden;">
                       
                            <img src="/Assets/Images/<%= (string.IsNullOrEmpty(l.Image)) ? "default.png" : l.Image %>" />
                       
                       </div>
                    </td>
                    <td>
                    <%if (!string.IsNullOrEmpty(l.Description))
                       { %>
                       <div >
                        <p style="padding-top:5px;clear:both;white-space: normal;word-wrap:break-word;"> 
                            <%= (l.Description.Length > 200) ? l.Description.Substring(0, 200) + "..." : l.Description %>
                        </p>
                       </div>
                     
                    <%} %>
                    </td>
                    
                  </tr>
                  <tr><td></td><td align="right"><a href="/Directory/Listing/<%=l.Id %>">> See full listing</td></tr>
              </table>
             
             
          </div>
          
          <br /> 
          <br />
          
          
        <%} %>
    </div>
    <div class="clear"></div>
    </div><!--end of right content-->
<div class="clear"></div>
</div><!--end of center content-->
<script type="text/javascript">
    function Show(tab) {
        switch(tab)
        {
        case 1: //categories
            $('#counties').css("display", "none");
            $('#featured').css("display", "none");
            $('#categories').css("display", "block");

            $('#featured-link').removeClass("active");
            $('#county-link').removeClass("active");
            $('#category-link').addClass("active");
            break;
        
        case 2: //counties
            $('#categories').css("display", "none");
            $('#counties').css("display", "block");
            $('#featured').css("display", "none");

            $('#featured-link').removeClass("active");
            $('#category-link').removeClass("active");
            $('#county-link').addClass("active");
            break;
        case 3: //featured
            $('#categories').css("display", "none");
            $('#counties').css("display", "none");
            $('#featured').css("display", "block");

            $('#county-link').removeClass("active");
            $('#category-link').removeClass("active");
            $('#featured-link').addClass("active");
            break;
        default:
            break;  
        }

    }
    function ShowSubs() {
        
       
        if ($('.sub').css("display") == "block") {
            $('.sub').css("display", "none");
            $('#toggle').html('<img src="/Assets/Images/plus.gif" style="vertical-align:baseline"/>&nbsp;<a class="subcatHead2" href="#" onclick="ShowSubs(); return false;">Expand all categories</a>');
            return;
        }
        else {
            $('.sub').css("display", "block");
            $('#toggle').html('<img src="/Assets/Images/minus.gif" style="vertical-align:baseline"/>&nbsp;<a class="subcatHead2" href="#" onclick="ShowSubs(); return false;">Collapse all categories</a>');
            return;
        }
    }
</script>
</asp:Content>

